<?php namespace web\admin\controller;


class Message
{

	function __construct()
	{
		Middleware::set('bootstrap');
		Middleware::run();
		User::isLogin();
	}

	//消息列表
	public function lists()
	{
		$module = Request::get( 'm' );
		$Page=Page::row(4)->make(Db::table( 'keywords' )->where( 'module', $module )->count());
		$data   = Db::table( 'keywords' )->where( 'module', $module )->limit(Page::limit())->get();
		View::with('Page',$Page);
		View::with('data',$data)->make();
	}

	//添加关键字
	public function post()
	{
		$module=Request::get('m');
		$class  = 'module\\' . $module . '\Message';
		$obj    = new $class;
		if (IS_POST) {
			$keyword = new \system\model\Keyword();
			if ($kid=$keyword->store()) {
				$obj->submit($kid);
				message( '保存成功', u( 'lists', [ 'm' => $_GET['m'] ] ), 'success' );
			}else{
				message( $keyword->getError(), '', 'error' );
			}
		}
		View::with( 'messageField', $obj->display() );
		View::make();
	}

	public function system()
	{
		if (IS_POST) {
			$model=new \system\model\Config();
			if ($model->edit(1)) {
				message( '保存成功', 'refresh', 'success' );
			}else{
				message( $model->getError(), '', 'error' );
			}
		}
		View::make();
	}

	public function welcome()
	{
		if (IS_POST) {
			$model=new \system\model\Config();
			if ($model->edit(2)) {
				message( '保存成功', 'refresh', 'success' );
			}else{
				message( $model->getError(), '', 'error' );
			}
		}
		View::make();
	}

}